/***********************************************************************
 * Module:  VRSTA_PLOCE.java
 * Author:  Igor Spremo
 * Purpose: Defines the Class VRSTA_PLOCE
 ***********************************************************************/

package model.entity;

import java.io.Serializable;
import java.util.Collection;
import java.util.Iterator;
import java.util.Vector;

/**
 * 
 * @author Igor Spremo, Milan Stojkov
 *
 */

@SuppressWarnings("serial")
public class VrstaPloce implements Serializable {
	
	protected Integer id;
	protected String naziv;
	protected int verzija;

	protected Collection<Saradnik> saradnici;

	public Collection<Saradnik> getSaradnici() {
		if (saradnici == null)
			saradnici = new Vector<Saradnik>();
		
		return saradnici;
	}

	public Iterator<Saradnik> getIteratorSaradnici() {
		if (saradnici == null)
			saradnici = new Vector<Saradnik>();
		
		return saradnici.iterator();
	}

	public void setSaradnici(Collection<Saradnik> newSaradnici) {
		removeAllSaradnici();
		for (Iterator<Saradnik> iter = newSaradnici.iterator(); iter.hasNext();)
			addSaradnik((Saradnik) iter.next());
	}

	public void addSaradnik(Saradnik newSaradnik) {
		if (newSaradnik == null)
			return;
		if (this.saradnici == null)
			this.saradnici = new Vector<Saradnik>();
		if (!this.saradnici.contains(newSaradnik)) {
			this.saradnici.add(newSaradnik);
			newSaradnik.addVrstaPloce(this);
		}
	}

	public void removeSaradnik(Saradnik oldSaradnik) {
		if (oldSaradnik == null)
			return;
		if (this.saradnici != null)
			if (this.saradnici.contains(oldSaradnik)) {
				this.saradnici.remove(oldSaradnik);
				oldSaradnik.removeVrstaPloce(this);
			}
	}

	public void removeAllSaradnici() {
		if (saradnici != null) {
			Saradnik oldSARADNIK;
			for (Iterator<Saradnik> iter = getIteratorSaradnici(); iter.hasNext();) {
				oldSARADNIK = (Saradnik) iter.next();
				iter.remove();
				oldSARADNIK.removeVrstaPloce(this);
			}
		}
	}

}